package net.yla.smartbus.module.ba.area.service.impl;

import net.yla.smartbus.module.ba.area.dto.Point;
import net.yla.smartbus.module.ba.area.entity.BaPoints;
import net.yla.smartbus.module.ba.area.form.PointsForm;
import net.yla.smartbus.module.ba.area.mapper.PointsMapper;
import net.yla.smartbus.module.ba.area.service.PointsService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 默苍离
 * @date 2021/7/5 10:51
 * <p>
 * ******************************************
 * @annotation:
 */
@Service
public class PointsServiceImpl implements PointsService {


    private final PointsMapper pointsMapper;

    public PointsServiceImpl(PointsMapper pointsMapper) {
        this.pointsMapper = pointsMapper;
    }


    /**
     * 保存坐标点集合
     *
     * @param pointsForm
     * @return
     */
    @Override
    public Integer save(PointsForm pointsForm) {

        //删除坐标点
        this.deletePoint(pointsForm.getRegionId());

        List<Point> pointsList = pointsForm.getPointsList();

        for (int i = 0; i < pointsList.size(); i++) {
            Point point = pointsList.get(i);
            pointsForm.setLatitude2(point.getLat());
            pointsForm.setLongitude2(point.getLng());

            pointsMapper.save(pointsForm);
        }
        return 1;

    }


    @Override
    public Integer update(Integer areaId) {
        return pointsMapper.update(areaId);
    }

    @Override
    public List<BaPoints> getPoint(Integer areaId) {
        return pointsMapper.getPoint(areaId);
    }


    /**
     * 删除坐标点
     *
     * @param areaId
     * @return
     */
    @Override
    public Integer deletePoint(Integer areaId) {
        return pointsMapper.deletePoint(areaId);
    }

}
